package cn.maihe.elg.operation.repository.entity;

import cn.maihe.elg.operation.repository.entity.SmsVo;
import cn.maihe.framework.starter.base.sql.BaseEntity;
import cn.maihe.framework.starter.base.sql.MapperInterface;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.IdType;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@TableName("t_sms")
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
@MapperInterface("cn.maihe.elg.operation.repository.mapper.SmsMapper")
public class SmsDO extends BaseEntity {
    /**
     * 主键
     */
    @TableId(type = IdType.ID_WORKER)
    private Long id;

    /**
     * 事件
     */
    @TableField(value = "event")
    private String event;

    /**
     * 手机号
     */
    @TableField(value = "mobile")
    private String mobile;

    /**
     * 验证码
     */
    @TableField(value = "code")
    private String code;

    /**
     * 验证次数
     */
    @TableField(value = "times")
    private Integer times;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    private Date createTime;

    /**
     * 短信内容
     */
    @TableField(value = "content")
    private String content;

    /**
     * 类型：1=短信验证，2=短信通知
     */
    @TableField(value = "sms_type")
    private Integer smsType;

    /**
     * 返回的code   ok=成功
     */
    @TableField(value = "res_code")
    private String resCode;

    public SmsVo buildVo() {
        return new SmsVo(id, event, mobile, code, times, createTime, content, smsType, resCode);
    }

    public static SmsDO of(SmsVo vo) {
        return new SmsDO(vo.getId(), vo.getEvent(), vo.getMobile(), vo.getCode(), vo.getTimes(), vo.getCreateTime(), vo.getContent(), vo.getSmsType(), vo.getResCode());
    }
}